package com.mdxx.xczd.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class FormatUtil {

	private static String[] week = {"日","一","二","三","四","五","六"};
	public static String getMedioName() {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat dateFormat = new   
				SimpleDateFormat("yyyyMMdd_HHmmss");
		return dateFormat.format(date);
	}

	public static String getdate(String str) {
		Date date = new Date(str);
		SimpleDateFormat dateFormat = new   
				SimpleDateFormat("yyyyMMdd");
		return dateFormat.format(date);

	}

	public static String getTime1(String str) {
		Date date = new Date(str);
		SimpleDateFormat dateFormat = new   
				SimpleDateFormat("HH:mm:ss");
		return dateFormat.format(date);

	}

	/*public static String getTime2(String str) {
		Date date = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			date = dateFormat.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}						
		SimpleDateFormat format = new   
				SimpleDateFormat("HH:mm");
		return format.format(date);
	}*/

	public static String getTime2() {
		Date date = new Date();
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		
		return dateFormat.format(date);
	}

	public static long[] getTimeDif(String str){
		long[] times = new long[3];
		Date now = new Date(System.currentTimeMillis());
		Date date = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			date = dateFormat.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}				
		long l=date.getTime() - now.getTime();
		/*long day=l/(24*60*60*1000);
		long hour=(l/(60*60*1000));
		long min=((l/(60*1000))-day*24*60-hour*60);
		long sec=(l/1000-day*24*60*60-hour*60*60-min*60);
		times[0] = hour;
		times[1] = min;
		times[2] = sec;	*/

		l = l/1000;
		long h = l/3600;
		long m = (l%3600)/60;
		long s = l-h*3600-m*60;
		times[0] = h;
		times[1] = m;
		times[2] = s;
		return times;		   
	}


	public static String getDateFor(){
		Date date = new Date();
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy年MM月dd日");
		return dateFormat.format(date).toString();
	}

	public static String getWeek(){
		Calendar calendar = Calendar.getInstance();
		int a = calendar.get(Calendar.DAY_OF_WEEK);        
		return "星期"+week[a-1];
	}

	public static String getPointDate() {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat dateFormat = new   
				SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(date);
	}

	public static String getSmallFileUrl(String str) {
		String fileUrl = str.substring(0, str.length()-4)+"_samll.jpg";
		return fileUrl;
	}

	/**
	 * yyyy-MM-dd HH:mm:ss  to  HH-mm
	 */
	public static String getTime3(String begin,String end){
		Date beginDate = null;
		Date endDate = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			beginDate = dateFormat.parse(begin);
			endDate = dateFormat.parse(end);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		SimpleDateFormat format = new  SimpleDateFormat("HH:mm");
		String time = format.format(beginDate)+" - "+format.format(endDate);
		return time;
	}

	/**
	 * yyyy-MM-dd HH:mm:ss  to  HH-mm
	 */
	public static String getTime3(String begin){
		Date beginDate = null;
		Date endDate = new Date(System.currentTimeMillis());
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			beginDate = dateFormat.parse(begin);
			//			endDate = dateFormat.parse(endDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		SimpleDateFormat format = new  SimpleDateFormat("HH:mm");
		String time = format.format(beginDate)+" - "+format.format(endDate);
		return time;
	}



	/**
	 * 开始前30分钟间隔的毫秒数
	 */
	public static long getTime4(String begin){
		Date currentDate = new Date();
		Date beginDate = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			beginDate = dateFormat.parse(begin);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long diff = beginDate.getTime()-currentDate.getTime()-30*60*1000;
		return diff;
	}

	/**
	 * 开始前间隔的毫秒数
	 */
	public static long getTime5(String begin){
		Date currentDate = new Date();
		Date beginDate = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			beginDate = dateFormat.parse(begin);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long diff = beginDate.getTime()-currentDate.getTime();
		return diff;
	}

	public static Long str2Date(String str) {
		Date date = null;
		SimpleDateFormat dateFormat = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			date = dateFormat.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}					
		return date.getTime();
	}
	
	public static Long str2Date() {
		Date date = new Date();		
		return date.getTime();
	}
	
	public static String getformatStr(long hour, long min, long second){
		String str = String.format("%02d", hour)+":"+String.format("%02d", min)+":"+String.format("%02d", second);
		return str;
	}

	public static String getSSSTime(long str) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
		String formatStr =formatter.format(str);
		return formatStr;
	}

}
